# Maintainer: Leonardo Arena <rnalrd@alpinelinux.org>
pkgname=pg_probackup
pkgver=2.5.13
_pgsqlver=15.5
_pgsqlverm="${_pgsqlver%%.[0-9]*}"
pkgrel=0
pkgdesc="Backup and recovery manager for PostgreSQL"
url="https://github.com/postgrespro/pg_probackup"
arch="all !riscv64 !loongarch64" # blocked by postgresql15
license="PostgreSQL"
makedepends="postgresql$_pgsqlverm postgresql$_pgsqlverm-dev zlib-dev readline-dev libxml2-utils libxslt"
source="pg_probackup-$pkgver.tar.gz::https://github.com/postgrespro/pg_probackup/archive/refs/tags/$pkgver.tar.gz
	https://ftp.postgresql.org/pub/source/v$_pgsqlver/postgresql-$_pgsqlver.tar.bz2"
builddir="$srcdir/postgresql-$_pgsqlver/contrib/pg_probackup-$pkgver"

prepare() {
	default_prepare

	mv "$srcdir"/pg_probackup-$pkgver "$srcdir"/postgresql-$_pgsqlver/contrib

	cd "$srcdir"/postgresql-$_pgsqlver
	./configure --without-ldap

	local _header
	for _header in $(ls "$srcdir"/postgresql-$_pgsqlver/src/bin/pg_basebackup/*.h); do
		ln -s $_header "$builddir"/src/
	done
}

build() {
	make -j1

	# fail to build
	# cd doc
	# xmllint --noout --valid probackup.xml
	# xsltproc stylesheet.xsl probackup.xml >pg-probackup.html
}

check() {
	local _tmp=$(mktemp -u)
	local _catalog="$(pwd)$_tmp"
	./pg_probackup version
	./pg_probackup init -B $_catalog
}

package() {
	install -Dm755 ./pg_probackup \
		"$pkgdir"/usr/bin/pg_probackup$_pgsqlverm
	# install -Dm644 "$builddir"/doc/pg-probackup.html "$pkgdir"/usr/share/doc/pg_probackup/pg-probackup.html
}

sha512sums="
0b4ee0d86e93fbd7cc5b1d271b8b7edbfe30d4cd00a730837ab19ac1e69281710d53aa177e94857e18afbaaa44eac61313ef8da56f07720402b7698adb9d16ef  pg_probackup-2.5.13.tar.gz
9ed9d160b3cef99954ccd47a970c107b7e3b0196a7d848f740bf3c52a1c626f6f457814c97f37b9f0467bb07734e19806a15bd9cf3c39445e1d89e75b37064cc  postgresql-15.5.tar.bz2
"
